import java.util.*;

public class GroupAnagrams {
    // leetcode hot 100 字母异位词
    // https://leetcode.cn/problems/group-anagrams/description/?envType=study-plan-v2&envId=top-100-liked
    public List<List<String>> groupAnagrams(String[] strs) {
        Map<String,List<String>> hash = new HashMap<>();
        for (String str : strs) {
            char[] tmp = str.toCharArray();
            Arrays.sort(tmp);
            String s = new String(tmp);
            if (hash.get(s) == null) {
                hash.put(s, new ArrayList<>());
            }
            hash.get(s).add(str);
        }
        return new ArrayList<>(hash.values());
    }
}
